package com.ddx.controller.core;

import com.ddx.common.exception.ExceptionUtil;
import com.ddx.common.exception.ResultModel;
import com.ddx.common.util.CommonUtils;
import com.ddx.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author: liyuxiang
 * @create: 2018-11-18
 */
@RestController
@RequestMapping(value = "/userCenter")
public class PersonalController {

    private static final Logger logger = LoggerFactory.getLogger(PersonalController.class);

    @Autowired
    IUserService iUserService;

    /**
     * 个人中心
     *
     * @return
     */
    @CrossOrigin(origins = "*", maxAge = 3600)
    @RequestMapping(value = "/getUserCenterInfo", method = RequestMethod.POST)
    public ResultModel getUserCenterInfo(HttpServletRequest request, @RequestBody Map<String, Object> map) {
        try {
            String masterUserId = request.getHeader("userId");
            String guestUserId = null;
            if (map.containsKey("guestUserId")) {
                guestUserId = String.valueOf(map.get("guestUserId"));
            }
            return iUserService.getUserCenterInfo(masterUserId, guestUserId);
        } catch (Exception e) {
            logger.error("getUserCenterInfo error{}", e);
            return ExceptionUtil.getMessageException(e);
        }
    }

}
